package com.senyin.utils;

import org.junit.jupiter.api.Test;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class ComMethods {

    public static String dateFormat(Date date){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        return sdf.format(date);
    }

    public static String dateTimeFormat(Date date){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return sdf.format(date);
    }

    public static String timeFormat(Date date){
        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
        return sdf.format(date);
    }

    public static Date getDate(String date) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        // 将字符串解析成日期对象
        return sdf.parse(date);
    }

    @Test
    public void test(){
        System.out.println(dateFormat(new Date()));
        System.out.println(dateTimeFormat(new Date()));
        System.out.println(timeFormat(new Date()));
    }

    @Test
    public void getDate() throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        // 将字符串解析成日期对象
        Date date = sdf.parse("2000-10-18");
        System.out.println(date);
    }
}
